/*
 *  CONLLConverter.h
 *  Dictionary
 *
 *  Created by Rune Laugesen on 22/07/11.
 *  Copyright 2011 Copenhagen University. All rights reserved.
 *
 */

#ifndef Dictionary_CONLLConverter_h
#define Dictionary_CONLLConverter_h


#include "Instances.h"

#define LINEBUFFER 256

using namespace std;

struct Conll {
	int ID;
	string  FORM;
	string  LEMMA;
	string  CPOSTAG;
	string  POSTAG;
	string  FEATS;
	int     HEAD;
	string  DEPREL;
	string  PHEAD;
	string  PDEPREL;
};

class CONLLConverter 
{    
private:
    inline static string StringToLower(string strToConvert)
    {
        for(unsigned int i=0;i<strToConvert.length();i++)
        {
            strToConvert[i] = tolower(strToConvert[i]);
        }
        return strToConvert;//return the converted string
    };
public:
    inline static vector< vector<string> > ReadToSWPS(string filename)
    {
        vector< vector<string> > data(3);
        
        ifstream file(filename.c_str());
        char line[LINEBUFFER];
        
        while (!file.eof())
        {
            Conll conllline;        
            
            file.getline(line, LINEBUFFER, '\n');
            
            //New sentance insert blank
            if (line[0] == '\0' || line[0] == '\t')
            {
                data[WORD].push_back("");
                data[LEMMA].push_back("");
                data[POS].push_back("");
                continue;
            }
            
            conllline.ID = atoi(strtok(line, "	"));
            conllline.FORM = strtok(NULL, "	");
            conllline.LEMMA = strtok(NULL, "	");
            conllline.CPOSTAG = strtok(NULL, "	");
            conllline.POSTAG = strtok(NULL, "	");
            conllline.FEATS = strtok(NULL, "	");
            conllline.HEAD = atoi(strtok(NULL, "	"));
            conllline.DEPREL = strtok(NULL, "	");
            //conllline.PHEAD = strtok(NULL, "	");
            //conllline.PDEPREL = strtok(NULL, "	");
            
            if (conllline.FORM.length() == 1)
                continue;
            data[WORD].push_back(CONLLConverter::StringToLower(conllline.FORM));
            data[LEMMA].push_back(conllline.LEMMA);
            data[POS].push_back(conllline.CPOSTAG);
        }
        return data;
        
    }; 
};

#endif
